/*
Copyright [2020] [https://www.stylefeng.cn]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Guns采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：

1.请不要删除和修改根目录下的LICENSE文件。
2.请不要删除和修改Guns源码头部的版权声明。
3.请保留源码和相关描述文件的项目出处，作者声明等。
4.分发源码时候，请注明软件出处 https://gitee.com/stylefeng/guns-separation
5.在修改包名，模块名称，项目代码等时，请注明软件出处 https://gitee.com/stylefeng/guns-separation
6.若您的项目无法满足以上几点，可申请商业授权，获取Guns商业授权许可，请在官网购买授权，地址为 https://www.stylefeng.cn
 */
package cn.stylefeng.guns.sys.modular.user.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.annotion.Permission;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.sys.modular.user.controller.dto.GetHuifuMsgDTO;
import cn.stylefeng.guns.sys.modular.user.controller.vo.GetHuifuMsgVO;
import cn.stylefeng.guns.sys.modular.user.controller.vo.SettleOrUpdateCommissionVO;
import cn.stylefeng.guns.sys.modular.user.param.SysTenantAddParam;
import cn.stylefeng.guns.sys.modular.user.param.SysTenantEditParam;
import cn.stylefeng.guns.sys.modular.user.param.SysTenantParam;
import cn.stylefeng.guns.sys.modular.user.service.SysTenantService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统用户控制器
 *
 * @author xuyuxiang
 * @date 2020/3/19 21:14
 */
@RestController
public class SysTenantController {

    @Resource
    private SysTenantService sysTenantService;

    /**
     * 查询租户列表
     *
     * @author xuyuxiang
     * @date 2020/3/20 21:00
     */
    @Permission
    @PostMapping("/sysTenant/page")
    @BusinessLog(title = "查询租户列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(@RequestBody SysTenantParam sysTenantParam) {
        return new SuccessResponseData(sysTenantService.page(sysTenantParam));
    }


    @PostMapping("/sysTenant/loginList")
    @BusinessLog(title = "首页登录租户列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData loginList(@RequestBody SysTenantParam sysTenantParam) {
        return new SuccessResponseData(sysTenantService.loginList(sysTenantParam));
    }

    /**
     * 查询全部租户列表
     *
     * @author xuyuxiang
     * @date 2020/3/20 21:00
     */
    @PostMapping("/sysTenant/list")
    @BusinessLog(title = "查询全部租户列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(@RequestBody SysTenantParam sysTenantParam) {
        return new SuccessResponseData(sysTenantService.list(sysTenantParam));
    }

    /**
     * 添加租户、企业用户基本信息开户、用户业务入驻
     *
     * @author xuyuxiang
     * @date 2020/3/20 21:00
     */
    @Permission
    @PostMapping("/sysTenant/add")
    @BusinessLog(title = "添加租户", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@Validated @RequestBody SysTenantAddParam sysTenantParam) {
        return sysTenantService.add(sysTenantParam);

    }


    @Permission
    @PostMapping("/sysTenant/resetPasswords")
    @BusinessLog(title = "重置账号密码", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData update(@RequestBody SysTenantEditParam sysTenantParam) {
        sysTenantService.resetPasswords(sysTenantParam);
        return new SuccessResponseData();
    }


    @Permission
    @PostMapping("/sysTenant/edit")
    @BusinessLog(title = "编辑租户", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData edit(@RequestBody SysTenantEditParam sysTenantParam) {
        sysTenantService.edit(sysTenantParam);
        return new SuccessResponseData();
    }


    @Permission
    @PostMapping("/sysTenant/editStatus")
    @BusinessLog(title = "修改租户状态", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData editStatus(@RequestBody SysTenantEditParam sysTenantParam) {
        sysTenantService.editStatus(sysTenantParam);
        return new SuccessResponseData();
    }


    @Permission
    @PostMapping("/sysTenant/detail")
    @BusinessLog(title = "租户详情", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData detail(@RequestBody SysTenantEditParam sysTenantParam) {
        return sysTenantService.detail(sysTenantParam);
    }

    /**
     * 重新分配菜单
     *
     * @author xuyuxiang
     * @date 2020/3/20 21:00
     */
    @Permission
    @PostMapping("/sysTenant/grantMenu")
    @BusinessLog(title = "重新分配菜单", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData grantMenu(@RequestBody SysTenantEditParam sysTenantParam) {
        sysTenantService.grantMenu(sysTenantParam);
        return new SuccessResponseData();
    }

    /**
     * 修改状态
     *
     * @author xuyuxiang
     * @date 2020/5/25 14:32
     */
    @Permission
    @PostMapping("/sysTenant/changeStatus")
    @BusinessLog(title = "修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData changeStatus(@RequestBody SysTenantParam sysUserParam) {
        sysTenantService.changeStatus(sysUserParam);
        return new SuccessResponseData();
    }

    /**
     * 根据租户id查询入驻汇付信息
     */
    @Permission
    @PostMapping("/sysTenant/getHuifuMsg")
    @BusinessLog(title = "获取汇付信息", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData<GetHuifuMsgDTO> getHuifuMsg(@Validated @RequestBody GetHuifuMsgVO getHuifuMsgVO) {
        return sysTenantService.getHuifuMsg(getHuifuMsgVO);
    }

    /**
     * 入驻汇付或者修改手续费
     */
    @Permission
    @PostMapping("/sysTenant/settleOrUpdateCommission")
    @BusinessLog(title = "入驻汇付或者修改手续费", opType = LogAnnotionOpTypeEnum.UPDATE)
    public ResponseData settleOrUpdateCommission(@Validated @RequestBody SettleOrUpdateCommissionVO settleOrUpdateCommissionVO) {
        return sysTenantService.settleOrUpdateCommission(settleOrUpdateCommissionVO);
    }

    /**
     * 验证登录状态/用户状态/用户角色是否变更
     *
     * @author xuyuxiang
     * @date 2020/3/20 21:00
     */
    @PostMapping("/sysTenant/checkStatus")
    public ResponseData checkStatus() {
        return ResponseData.success();
    }

}
